Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add region resource volume #778

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

Tiboau
Copy link
Contributor

@Tiboau Tiboau commented Nov 21, 2024

Description

Resource volume

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • Documentation update

How Has This Been Tested?

make testacc TESTARGS="-run TestAccCloudProjectVolume_basic"
TF_ACC=1 go test $(go list ./... |grep -v 'vendor') -v -run TestAccCloudProjectVolume_basic -timeout 600m -p 10
?       github.com/ovh/terraform-provider-ovh   [no test files]
?       github.com/ovh/terraform-provider-ovh/ovh/helpers       [no test files]
?       github.com/ovh/terraform-provider-ovh/ovh/types [no test files]
=== RUN   TestAccCloudProjectVolume_basic
    provider_test.go:430: Read Cloud Project /cloud/project/bad3308a4b4d4dcba4d15d5b082d7225 -> status: 'ok', desc: 'Production'
--- PASS: TestAccCloudProjectVolume_basic (13.20s)
PASS
ok      github.com/ovh/terraform-provider-ovh/ovh       13.214s
testing: warning: no tests to run
PASS
ok      github.com/ovh/terraform-provider-ovh/ovh/helpers/hashcode      (cached) [no tests to run]

Test Configuration:

  • Terraform version: terraform version: Terraform vx.y.z
  • Existing HCL configuration you used:
resource "ovh_cloud_project_volume" "vols" {
   region_name = "yyyy"
   service_name = "xxxxx"
   description = "test"
   name = "monvolume"
   size = 15
   type = "classic"
}

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings or issues
  • I have added acceptance tests that prove my fix is effective or that my feature works
  • New and existing acceptance tests pass locally with my changes

MinTimeout: 3 * time.Second,
}

_, err := stateConf.WaitForStateContext(ctx)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should retrieve the last result instead like the following:

res, err := stateConf.WaitForStateContext(ctx)

return res, err

and use res in create func, so that you can remove lines 76-84.

return
}

endpoint := "/cloud/project/" + url.PathEscape(data.ServiceName.ValueString()) + "/region/" + url.PathEscape(data.RegionName.ValueString()) + "/volume/" + url.PathEscape(data.VolumeId.ValueString()) + ""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
endpoint := "/cloud/project/" + url.PathEscape(data.ServiceName.ValueString()) + "/region/" + url.PathEscape(data.RegionName.ValueString()) + "/volume/" + url.PathEscape(data.VolumeId.ValueString()) + ""
endpoint := "/cloud/project/" + url.PathEscape(data.ServiceName.ValueString()) + "/region/" + url.PathEscape(data.RegionName.ValueString()) + "/volume/" + url.PathEscape(data.VolumeId.ValueString())

}

// Update resource
endpoint := "/cloud/project/" + url.PathEscape(data.ServiceName.ValueString()) + "/region/" + url.PathEscape(data.RegionName.ValueString()) + "/volume"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when using POST on this route, won't it just recreate a new volume ?
Shouldn't you use PUT /cloud/project/{serviceName}/volume/{volumeId} instead ?

}

// Read updated resource
endpoint = "/cloud/project/" + url.PathEscape(data.ServiceName.ValueString()) + "/region/" + url.PathEscape(data.RegionName.ValueString()) + "/volume/" + url.PathEscape(data.VolumeId.ValueString()) + ""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
endpoint = "/cloud/project/" + url.PathEscape(data.ServiceName.ValueString()) + "/region/" + url.PathEscape(data.RegionName.ValueString()) + "/volume/" + url.PathEscape(data.VolumeId.ValueString()) + ""
endpoint = "/cloud/project/" + url.PathEscape(data.ServiceName.ValueString()) + "/region/" + url.PathEscape(data.RegionName.ValueString()) + "/volume/" + url.PathEscape(data.VolumeId.ValueString())

}

// Delete API call logic
endpoint := "/cloud/project/" + url.PathEscape(data.ServiceName.ValueString()) + "/volume/" + url.PathEscape(data.VolumeId.ValueString()) + ""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
endpoint := "/cloud/project/" + url.PathEscape(data.ServiceName.ValueString()) + "/volume/" + url.PathEscape(data.VolumeId.ValueString()) + ""
endpoint := "/cloud/project/" + url.PathEscape(data.ServiceName.ValueString()) + "/volume/" + url.PathEscape(data.VolumeId.ValueString())

),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("ovh_cloud_project_volume.volume", "region_name", os.Getenv("OVH_CLOUD_PROJECT_REGION_TEST")),
resource.TestCheckResourceAttr("ovh_cloud_project_volume.volume", "service_name", os.Getenv("OVH_CLOUD_PROJECT_SERVICE_TEST")),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
resource.TestCheckResourceAttr("ovh_cloud_project_volume.volume", "service_name", os.Getenv("OVH_CLOUD_PROJECT_SERVICE_TEST")),
resource.TestCheckResourceAttr("ovh_cloud_project_volume.volume", "service_name", serviceName),


The following arguments are supported:

* `service_name` - The id of the public cloud project. If omitted, the `OVH_CLOUD_PROJECT_SERVICE` environment variable is used. **Changing this value recreates the resource.**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* `service_name` - The id of the public cloud project. If omitted, the `OVH_CLOUD_PROJECT_SERVICE` environment variable is used. **Changing this value recreates the resource.**
* `service_name` - Required. The id of the public cloud project. **Changing this value recreates the resource.**

doesn't seem true

The following arguments are supported:

* `service_name` - The id of the public cloud project. If omitted, the `OVH_CLOUD_PROJECT_SERVICE` environment variable is used. **Changing this value recreates the resource.**
* `region_name` - A valid OVHcloud public cloud region name in which the volume will be available. Ex.: "GRA11". **Changing this value recreates the resource.**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* `region_name` - A valid OVHcloud public cloud region name in which the volume will be available. Ex.: "GRA11". **Changing this value recreates the resource.**
* `region_name` - Required. A valid OVHcloud public cloud region name in which the volume will be available. Ex.: "GRA11". **Changing this value recreates the resource.**

Comment on lines +83 to +88
"region_name": schema.StringAttribute{
CustomType: ovhtypes.TfStringType{},
Required: true,
Description: "Region name",
MarkdownDescription: "Region name",
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"region_name": schema.StringAttribute{
CustomType: ovhtypes.TfStringType{},
Required: true,
Description: "Region name",
MarkdownDescription: "Region name",
},
"region_name": schema.StringAttribute{
CustomType: ovhtypes.TfStringType{},
Required: true,
Description: "Region name",
MarkdownDescription: "Region name",
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
},
},

and same for other fields that should trigger a replace (at least service_name, size and type) if the doc is correct

Comment on lines +43 to +44
* `size` - Size of the volume **Changing this value recreates the resource.**
* `id` - id of the volume **Changing this value recreates the resource.**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* `size` - Size of the volume **Changing this value recreates the resource.**
* `id` - id of the volume **Changing this value recreates the resource.**
* `size` - Size of the volume
* `id` - id of the volume

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants